const {
  verify
} = require('../utils/tools');

//判断用户是否登录
const auth = (req, res, next) => {
  //拿到前端传过来的token
  let token = req.get('X-Access-Token');
  try {
    //验证token
    let result = verify(token);
    next()
  } catch (e) {
    res.render('fail', {
      data: JSON.stringify({
        message: 'X-Access-Token信息失效，请登录!'
      })
    });
  }
}

module.exports = {
  auth
}